package com.zhuiyun.project.api.apppatient.controller;

import com.zhuiyun.project.api.apppatient.entity.Patient;
import com.zhuiyun.project.api.apppatient.model.PatientModel;
import com.zhuiyun.project.api.apppatient.service.Impl.PatientServiceImpl;
import com.zhuiyun.project.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName PatientController
 * @Description TODO  病例
 * @Author Root
 * @Date 2023/7/3 14:37
 **/
@RestController
@RequestMapping("patient")
@CrossOrigin
public class PatientController {
    @Autowired
    PatientServiceImpl patientService;
    /**
    * @Author Root
    * @Description 录入病例
    * @Date 2023/7/3 14:39
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param patientModel
    */
    @PostMapping("/insertPatient")
    public CommonResult insertPatient(@RequestBody PatientModel patientModel){
        return patientService.insertPatient(patientModel);
    }
    /**
    * @Author Root
    * @Description 通过名字查询病例
    * @Date 2023/7/3 16:55
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param name
    */
    @GetMapping("/getPatientByName")
    public CommonResult getPatientByName(Integer userId,String cycle,String disease) {
        return patientService.getPatientByName(userId,cycle,disease);
    }
    /**
    * @Author Root
    * @Description 通过名字查询周期
    * @Date 2023/7/24 17:22
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param name
    */
    @GetMapping("/getPatientByCycle1")
    public CommonResult getPatientByCycle1(Integer userId) {
        return patientService.getPatientByCycle1(userId);
    }
    /**
     * @Author Root
     * @Description 通过名字查询周期
     * @Date 2023/7/24 17:22
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param name
     */
    @GetMapping("/getPatientByCycle2")
    public CommonResult getPatientByCycle2(Integer userId) {
        return patientService.getPatientByCycle2(userId);
    }
    /**
     * @Author Root
     * @Description 通过名字查询周期
     * @Date 2023/7/24 17:22
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param name
     */
    @GetMapping("/getPatientByCycle3")
    public CommonResult getPatientByCycle3(Integer userId) {
        return patientService.getPatientByCycle3(userId);
    }
    /**
     * @Author Root
     * @Description 通过名字查询周期
     * @Date 2023/7/24 17:22
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param name
     */
    @GetMapping("/getPatientByCycle4")
    public CommonResult getPatientByCycle4(Integer userId) {
        return patientService.getPatientByCycle4(userId);
    }
    @PostMapping("/updatePatientByName")
    public CommonResult updatePatientByName(@RequestBody Map map) {
        //map中存储的数据取出老的名字与新的名字
        String name = map.get("name").toString();
        String newName = map.get("newName").toString();
        return patientService.updatePatientByName(name,newName);
    }
    @PostMapping("/updatePatientById")
    public CommonResult updatePatientById(@RequestBody Patient patient) {
        return CommonResult.ok(patientService.updatePatientById(patient));
    }
}
